<script setup>

import {onMounted, reactive, ref} from "vue";
import {RULE} from "../../../const/index.js";
import {ElMessage} from "element-plus";
import router from "../../../router/index.js";
import MyNav from "../../../components/MyNav.vue";
import {listApi, updateApi} from "../../../api/axios.js";
import MyForm from "../../../components/MyForm.vue";
import {getResponseData} from "../../../request/index.js";

// 部门记录
let menu = JSON.parse(sessionStorage.getItem('row'));

// 路径导航
const navItems = [
  {icon: 'Avatar', label: '菜单管理', url: '/Menu'},
  {icon: 'HomeFilled', label: '菜单列表', url: '/Menu'},
  {icon: 'Edit', label: '修改菜单'},
];

//  表单项 + 表单值 + 表单规则
let items = ref([
  {label: '菜单名称', prop: 'title', required: true, span: 12},
  {label: '菜单图标', prop: 'icon', type: 'icon', required: true},
  // {label: '父菜单', prop: 'pid'},
  {label: '菜单描述', prop: 'info', type: 'textarea'},
]);
let params = reactive(menu);
let rules = {title: RULE.TITLE, info: RULE.INFO};

/* ================= 修改成功后 ================= */
function updateSuccess() {
  ElMessage.success('修改记录成功');
  setTimeout(() => router.push('/Menu'), 1000);
}

</script>

<template>
  <my-nav :items="navItems"/>
  <el-card class="menu-update-card" header="修改菜单">
    <my-form type="update"
             :items="items"
             :params="params"
             :rules="rules"
             :api="updateApi"
             :args="{module: 'menu'}"
             :callback="updateSuccess"/>
  </el-card>
</template>

<style scoped lang="scss">
.menu-update-card {
  width: 60%;
  margin: 65px auto 0;
}
</style>